﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class delete_bug : CommonPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);


            security = new Security();
            security.check_security(HttpContext.Current, Security.ANY_USER_OK_EXCEPT_GUEST);

            if (security.user.is_admin || security.user.can_delete_bug)
            {
                //
            }
            else
            {
                Response.Write("You are not allowed to use this page.");
                Response.End();
            }

            string id = Bug_Util.sanitize_integer(Request["id"]);

            int permission_level = btnet.Bug.get_bug_permission_level(Convert.ToInt32(id), security);
            if (permission_level != Security.PERMISSION_ALL)
            {
                Response.Write("You are not allowed to edit this item");
                Response.End();
            }

            if (IsPostBack)
            {

                Bug.delete_bug(Convert.ToInt32(row_id.Value));
                Server.Transfer("bugs.aspx");

            }
            else
            {

                titl.Text = Bug_Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                    + "delete " + SingularBugLabel;

                back_href.HRef = "edit_bug.aspx?id=" + id;

                sql = @"select bg_short_desc from bugs where bg_id = $1";
                sql = sql.Replace("$1", id);

                DataRow dr = DbUtil.get_datarow(sql);

                confirm_href.InnerText = "confirm delete of "
                        + SingularBugLabel
                        + ": "
                        + Convert.ToString(dr["bg_short_desc"]);

                row_id.Value = id;
            }
        }
    }
}
